//package com.zhousb.deviceManager.websocket;
//
//import lombok.NonNull;
//import org.springframework.http.server.ServerHttpRequest;
//import org.springframework.http.server.ServerHttpResponse;
//import org.springframework.http.server.ServletServerHttpRequest;
//import org.springframework.stereotype.Component;
//import org.springframework.web.socket.WebSocketHandler;
//import org.springframework.web.socket.server.HandshakeInterceptor;
//
//import java.util.Map;
//
//@Component
//public class WebSocketInterceptor implements HandshakeInterceptor {
//
////    @Override
////    public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
////        return false;
////    }
//
//    @Override
//    public boolean beforeHandshake(@NonNull ServerHttpRequest request, @NonNull ServerHttpResponse response, @NonNull WebSocketHandler wsHandler, @NonNull Map<String, Object> attributes) throws Exception {
//        System.out.println("1");
//        if (request instanceof ServletServerHttpRequest) {
//            ServletServerHttpRequest servletServerHttpRequest = (ServletServerHttpRequest) request;
//            // 模拟用户（通常利用JWT令牌解析用户信息）
//            String userId = servletServerHttpRequest.getServletRequest().getParameter("uid");
//            // TODO 判断用户是否存在
//            attributes.put("uid", userId);
//            return true;
//        }
//        return false;
//    }
//
//    @Override
//    public void afterHandshake(@NonNull ServerHttpRequest request, @NonNull ServerHttpResponse response, @NonNull WebSocketHandler wsHandler, Exception exception) {
//        System.out.println("2");
//    }
//}